package com.commerce.afive;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.Toast;

import com.commerce.afive.Activity.DialogActivity;
import com.commerce.afive.Activity.NormalActivity;
import com.commerce.afive.Retrofit.RetrofitActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.w("TAG","onCreate");
        Button btnFinish = findViewById(R.id.mn_btn_finish);
        Button btnToActivity = findViewById(R.id.mn_btn_toActivity);
        Button btnToNormal = findViewById(R.id.mn_btn_toNormal);
        Button btnToDialog = findViewById(R.id.mn_btn_toDialog);
        Button btnToRet = findViewById(R.id.mn_btn_toRet);
        btnFinish.setOnClickListener(this);
        btnToActivity.setOnClickListener(this);
        btnToNormal.setOnClickListener(this);
        btnToDialog.setOnClickListener(this);
        btnToRet.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        String strToast = "";
        switch (item.getItemId()){
            case R.id.main_add_item:
                strToast = "you click add";
                break;
            case R.id.main_remove_item:
                strToast = "you click remove";
                break;
        }
        Toast.makeText(MainActivity.this,strToast,Toast.LENGTH_LONG).show();
        return true;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.mn_btn_finish:
                finish();
                break;
            case R.id.mn_btn_toActivity:
                startActivityForResult(new Intent(MainActivity.this,SecondActivity.class).putExtra("extra_data","Hello SecondActivity"),1);
                break;
            case R.id.mn_btn_toNormal:
                startActivity(new Intent(MainActivity.this, NormalActivity.class));
                break;
            case R.id.mn_btn_toDialog:
                startActivity(new Intent(MainActivity.this, DialogActivity.class));
                break;
            case R.id.mn_btn_toRet:
                startActivity(new Intent(MainActivity.this, RetrofitActivity.class));
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        switch (requestCode) {
            case 1:
                if (resultCode == 2) {
                    Log.d("TAG", "onActivityResult: " + data.getStringExtra("data_return"));
                }
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.w("TAG","onStart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.w("TAG","onStop");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.w("TAG","onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.w("TAG","onPause");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.w("TAG","onDestroy");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.w("TAG","onRestart");
    }
}